package ProcessList;
import Gui.GameObjects.GameObject;
import ProcessManager.Process;

public class MoveMainObject extends Process {
	public static final double CLOSEENOUGH = 0.5;
	
	private GameObject Object;
	private double DistanceX;
	private double DistanceY;
	private double DestinationX;
	private double DestinationY;
	private int TimeToTake;

	public MoveMainObject(GameObject a_Object, int a_DestinationX,
			int a_DestinationY, int a_TimeToTake) {
		super("MoveMainObject");
		Object = a_Object;
		DestinationX = a_DestinationX;
		DestinationY = a_DestinationY;
		TimeToTake = a_TimeToTake;
		DistanceX = DestinationX - Object.GetX();
		DistanceY = DestinationY - Object.GetY();
	}

	public void destroy() {
	}

	public void UpdateProcess(int milliseconds) {
		double getx = Object.GetX();
		double gety = Object.GetY();

		// Are we close enough to y yet?
		if ((gety < DestinationY - CLOSEENOUGH) || (gety > DestinationY + CLOSEENOUGH)) {
			double YValue = (DistanceY / TimeToTake) * milliseconds;
			YValue += gety;
			Object.SetY(YValue);
		} else {
			Object.SetY(DestinationY);
		}

		// Are we close enough to x yet?
		if ((getx < DestinationX - CLOSEENOUGH) || (getx > DestinationX + CLOSEENOUGH)) {
			double XValue = (DistanceX / TimeToTake) * milliseconds;
			XValue += getx;
			Object.SetX(XValue);
		} else {
			Object.SetX(DestinationX);
		}

		// Are we there yet?
		if (getx == DestinationX && gety == DestinationY) {
			SetKill(true);
		}
	}

}
